package com.junmo.oauth.config.oauth2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;
import org.springframework.stereotype.Service;

import javax.sql.DataSource;

@Service
// 测试环境下的配置
public class MyClientDetailsService extends JdbcClientDetailsService {
    @Autowired
    public MyClientDetailsService(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        return super.loadClientByClientId(clientId);
    }
}






//// 生产环境下的配置
//public class MyClientDetailsService implements ClientDetailsService {
//    @Autowired
//    private AuthClientDetailsMapper authClientDetailsMapper;
//    @Override // 根据 clientId 读取oauth_client_details 表的客户端信息
//    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
//        AuthClientDetails clientDetails = authClientDetailsMapper.selectClientDetailsByClientId(clientId);
//        if (clientDetails == null) {
//            throw new ClientRegistrationException("该客户端不存在");
//        }
//        MyClientDetails details = new MyClientDetails(clientDetails);
//        return details;
//    }
//}
